﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/SystemManagement/Views/Shared/LigerUI.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" language="javascript">

        var grid;

        $(function () {
            f_showGrid('');

            $("#toptoolbar").ligerToolBar({ items: [
                { text: '增加', click: f_add, icon: 'add' },
                { line: true },
                { text: '修改', click: f_modify, icon: 'modify' },
                { line: true },
                { text: '删除', click: f_delete, icon: 'delete' },
                { line: true },
                { text: '管理权限', click: f_editAuth }

            ]
            });

        });

        function f_add() {
            //hideColumn();

            w = f_openWindow('/SystemManagement/Role/RoleAdd', '添加角色', 500, 400);
        }



        function f_delete() {

            var row = grid.getSelectedRow();

            if (row) {

                $.ligerDialog.confirm('确定要删除选中的记录吗？', function (yes) {
                    if (yes) {
                        w = $.get('/SystemManagement/Role/DeleteRole', { roleId: row.roleId }, function (data) {
                            $.ligerDialog.success(data, function () {
                                f_reload();
                            });

                        });
                    }
                })

            } else {
                $.ligerDialog.warn('请选择要删除的记录！')

            }
        }

        function f_modify() {

            var row = grid.getSelectedRow();

            if (row) {
                w = f_openWindow('/SystemManagement/Role/RoleEdit/' + row.roleId, '修改角色信息', 500, 400);
            } else {
                $.ligerDialog.warn('请选择要修改的记录！')

            }


            //$.ligerWindow.show({ width: 500, height: 400, left: 100, top: 50, title: '修改用户信息', url: url });

        }


        function f_search() {

            grid.options.url = encodeURI('<%=Url.Action("GetUser","Role")%>' + '/?conditions=' + $.trim($("#txtCondtions").val()));
            f_reload();
            //f_showGrid($.trim($("#txtCondtions").val()));
        }

        function f_viewAuth() {
            var row = grid.getSelectedRow();

            if (row) {
               
                w = $.ligerDialog.open({ url: '/SystemManagement/Role/RoleAuthEdit/'+row.roleId, width: 640, height:500, title: '查看角色权限', modal: true });
            } else {
                $.ligerDialog.warn('请选择角色记录！')

            }
        }

        function f_editAuth() {
            var row = grid.getSelectedRow();

            if (row) {

                w = $.ligerDialog.open({ url: '/SystemManagement/Role/RoleAuthEdit/' + row.roleId, width: 640, height: 500, title: '查看角色权限', modal: true });
            } else {
                $.ligerDialog.warn('请选择角色记录！')

            }
        }

        function f_showGrid(conditions) {

            grid = $("#maingrid").ligerGrid({
                columns: [{ display: '主键', name: 'roleId', isAllowHide: false, hide: 1, width: 40 },
                    { display: '角色名', name: 'roleName' }, { display: '备注', name: 'description' },
                    { display: '创建日期', name: 'creationDate' }, { display: '修改日期', name: 'modifiedDate', isSort: true}],
                url: encodeURI('<%=Url.Action("GetRole","Role")%>' + '/?conditions=' + conditions), sortName: 'roleId',
                //data: { Rows: [{id:1,userName:2}],Total:12 },
                showTitle: false,
                //isScroll: false,
                dataAction: 'server',
                usePager: true,
                pageSize: 5,
                pageSizeOptions: [5, 10, 20, 50, 100, 1000],
                //checkbox: true,
                fixedCellHeight: false,
                width: '100%', height: '100%',
                rownumbers: true
                //alternatingRow:true
            });

        }


        function f_openWindow(url, title, width, height) {
            //return $.ligerWindow.show({ width: width, height: height, left: 200, top: 20, title: title, url: url });
            return $.ligerDialog.open({ url: url, width: width, height: height, title: title, modal: true });
        }

        var w;

        function f_close(result) {

            $.ligerDialog.success("保存成功！");
            w.close();

        }


        function f_reload() {
            //var manager = $("#maingrid")[0].manager;
            grid.loadData(true);

        }


    </script>
    <style type="text/css">
        body
        {
            overflow: hidden;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="toptoolbar">
    </div>
    <div class="l-panel-search">
        <input type="text" id="txtCondtions" style="width: 200px;" />
        <input type="button" id="btnSearch" onclick="f_search()" value="搜索" />
    </div>
    <div class="l-clear">
    </div>
    <div id="maingrid" style="margin: 0; padding: 0">
    </div>
</asp:Content>
